package com.xiaoxin.controller;

import com.xiaoxin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author xiaoxiaode
 * @date 2021-08-28-10:14
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /*
     * 获取请求验证码
     * 请求参数:phone (map)
     * 响应:void
     * */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        String phone = (String) map.get("phone");
        userService.sendMsg(phone);
        // return ResponseEntity.status(200).body("successful");
        return ResponseEntity.ok(null);
    }

    /*
     * 校验登录
     * /user/loginCheck
     * phone,code
     * */
    @PostMapping("/loginVerification")
    public ResponseEntity loginCheck(@RequestBody Map map) {
        // 调用map集合获取请求参数
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");
        // 调用userService完成登录
        Map retMap = userService.loginVerification(phone, code);
        // 构造返回
        return ResponseEntity.ok(retMap);
    }
}
